#include <stdio.h>
#include <omp.h>

#define NBIN 100000

void main() {
	int i;
	double step,x,sum=0.0,pi;
	step = 1.0/NBIN;

	omp_set_num_threads(8);
	#pragma omp parallel for \
	private(x) \
	shared(step, sum)
	for (i = 0; i < NBIN; i++) {
		x = (i + 0.5) * step;
		#pragma omp critical
		sum += 4.0 / (1.0 + x * x);
	}

	pi = sum * step;
	printf("PI = %f\n",pi);
}

